#include <bits/stdc++.h>
using namespace std;
long long int n, t;
int a[1000001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> t;
    long long int ans = 0;
    for (int j = 1; j <= t; j++) {
      cin >> a[j];
    }
    sort(a + 1, a + t + 1);
    a[t + 1] = -99999999;
    long long k = 1;
    for (int j = 1; j <= t; j++) {
      if (a[j] == a[j + 1]) {
        k++;
      } else {
        ans += (k * (k - 1)) / 2;
        k = 1;
      }
    }
    cout << (t * (t - 1)) / 2 - ans << endl;
  }
  return 0;
}